
import { EventManager } from "../../engine/EventManager";
import jhaoproto from "../../lib/net/protobuf/jhaoproto.js";
import { EventConfig } from "../config/EventConfig";

export class UserModel {
    public static instance: UserModel = new UserModel()


    public isLogin: boolean = false
    public isLogining: boolean = false

    public account: string;
    public userId: number
    public userName: string;
    public sex: number;
    public userPhoto: string;
    
    public coins: number;
    public diamond: number;

    public room_id:number = 0

    public static proto2Model(userProto:jhaoproto.JhaoProto.IUserInfo, model: UserModel = null) {
        if (!model) {
            model = new UserModel()
        }
        model.userId = userProto.userId
        model.userName = userProto.userName
        model.sex = userProto.sex
        model.userPhoto = userProto.userPhoto
        model.coins = userProto.coins
        model.diamond = userProto.diamond

        if(model.userId == UserModel.instance.userId){
            EventManager.instance.dispatch(EventConfig.Event_Update_UserInfo)
        }
        return model
    }


   
}